package org.eenie.kdassistant.utils.kdy_encode;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

public class KdyMD5Util {
    public static String toMD5(String paramString) {

        StringBuffer localStringBuffer = new StringBuffer();
        try {
            MessageDigest localMessageDigest = MessageDigest.getInstance("MD5");
            localMessageDigest.update(paramString.getBytes());
            for (int k : localMessageDigest.digest()) {
                int m = k;
                if (k < 0) {
                    m = k + 256;
                }
                if (m < 16) {
                    localStringBuffer.append("0");
                }
                localStringBuffer.append(Integer.toHexString(m));
            }
            return localStringBuffer.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }



    public static String getOnlyCode(Context context)
    {
        Date localDate = new Date();
        int i = (int)(Math.random() * 90.0D);
        Object localObject = context.getSharedPreferences("code", Context.MODE_PRIVATE);
        SharedPreferences.Editor localEditor = ((SharedPreferences)localObject).edit();
        String str = ((SharedPreferences)localObject).getString("only_code", "");
        localObject = str;
        if (TextUtils.isEmpty(str))
        {
            localObject = localDate.getTime() + "" + (i + 10);
            localObject = "K" + ((String)localObject).substring(1);
            localEditor.putString("only_code", (String)localObject);
            localEditor.commit();
        }
        return (String)localObject;
    }


}
